<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //求和
        // var arr = [1,2,3,4,5,6,7,8,9,10]

        // var num =0;

        // for(var i = 0;i<arr.length;i++){

        //     num = num + arr[i]

        // }
        // console.log(num)

        //求50年后的薪资，每年涨幅0.05
        // var money = 10000;
        // for(var i =1;i<=50;i++){
        //  money +=money*0.05
        // }
        // console.log(money)

        // var total=10000
        // var count = 0

        // while(count<50){
        //     total = total + total*0.05
        //     count ++
        // }
        // console.log(total);

        //递归
                            //函数参数初始化值
        function getTotal (total,count=0){
            console.log(total)
            console.log(count)

            total = total + total *0.05
            count = count + 1

            if(count < 50){
                return getTotal(total,count)
            }else{
                return total;
            }
        }
        var newTotal = getTotal(10000);

        console.log(newTotal)
     </script>
</body>
</html>